package com.aki.ai_property.service.impl;

import com.aki.ai_property.dao.AiHomeDao;
import com.aki.ai_property.entity.AiHome;
import com.aki.ai_property.service.intf.AiHomeService;
import com.aki.ai_property.util.StringUtil;
import com.aki.ai_property.vo.PageBean;
import com.aki.ai_property.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Author:WuChuangChuang
 * Date:2022/8/29 14:49
 */
@Service
public class AiHomeServiceImpl implements AiHomeService {
    @Autowired
    private AiHomeDao dao;

    /** 新增 */
    @Override
    public Result save(AiHome aiHome) {
        if (dao.save(aiHome) >0){
            return Result.ok("新增成功");
        }
        return Result.fail("新增失败");
    }

    /** 删除 */
    @Override
    public Result delete(int id) {
        if (dao.delete(id) >0){
            return Result.ok("删除成功");
        }
        return Result.fail("删除失败");
    }

    /** 修改 */
    @Override
    public Result update(AiHome aiHome) {
        if (dao.update(aiHome) >0){
            return Result.ok("修改成功");
        }
        return Result.fail("修改失败");
    }

    /** 查询 */
    @Override
    public PageBean selectPage(String name, int page, int limit) {
        if (StringUtil.isNotEmpty(name)){
            name="%"+"name"+"%";
        }
        int start = (page-1)*limit;
        return PageBean.ok(dao.selectCount(name),dao.selectPage(name, start, limit));
    }

    /** 查询全部 */
    @Override
    public Result all() {
        return Result.ok(dao.all());
    }
}
